<?php
use app\extra\weibo\SaeTOAuthV2;

session_start();
header('Content-Type: text/html; charset=UTF-8');
define("WB_AKEY", '3790507299');
define("WB_SKEY", 'e5e2de2f566aa4edf9ce53c35c594fc0');
define("WB_CALLBACK_URL", 'http://localhost/thinkphp-practice/application/extra/weibo/callback.php');

$o = new app\extra\weibo\SaeTOAuthV2( WB_AKEY , WB_SKEY );
echo $_REQUEST['code'];
if (isset($_REQUEST['code'])) {
	$keys = array();
	$keys['code'] = $_REQUEST['code'];
	$keys['redirect_uri'] = WB_CALLBACK_URL;
	try {
		$token = $o->getAccessToken( 'code', $keys ) ;
	} catch (OAuthException $e) {
	}
}

if ($token) {
	$_SESSION['token'] = $token;
	setcookie( 'weibojs_'.$o->client_id, http_build_query($token) );
?>
授权完成,<a href="{:url('index/index/index')}">进入你的微博列表页面</a><br />
<?php
} else {
?>
授权失败。
<?php
}
?>
